﻿using System;
using System.Collections.Generic;
using SilverChart.Configuration;

namespace SilverChart.Components {
    public abstract class CartesianCoordinateAxis : AxisBaseComponent{
        List<Element> datas = new List<Element>();
        public CartesianCoordinateAxis(AxisBase axisConfig) {
            AxisConfig = axisConfig;
        }

        public AxisBase AxisConfig { get; private set; }

        public virtual Double ValuePerTick { get; protected set; }

        public abstract Double MappingValueToAxis(Double value);
        public abstract Boolean MajorTick(Int32 tickCount);

        public virtual Double AxisWidth {
            get {
                return ActualWidth + Margin.Left + Margin.Right;
            }
        }

        public virtual Double AxisHeight {
            get {
                return ActualHeight + Margin.Top + Margin.Bottom;
            }
        }

        public override List<Element> Datas {
            get {
                if (datas.Count == 0) {
                    IList<CartesianCoordinateChart> charts = WidgetsManager.GetCompatibleComponents<CartesianCoordinateChart>();
                    if (charts == null) {
                        throw new InvalidOperationException("There isn't any Cartesian Coordinate based chart!");
                    }

                    foreach (CartesianCoordinateChart chart in charts) {
                        datas.Add(chart.Data);
                    }
                }
                return datas;
            }
        }

        public override string WidgetName {
            get { throw new NotImplementedException(); }
        }
    }
}
